home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 7.1 KB | 299 lines |
- package symantec.itools.awt;
-
-
- import java.awt.Canvas;
- import java.awt.Dimension;
-
-
- /**
- * Components based on this class are used to select
- * one value from a continuous range of values. It has a movable thumb in
- * front of a gauge with ticks marks on it.
- * <p>
- * @see symantec.itools.awt.HorizontalSlider
- * @see symantec.itools.awt.VerticalSlider
- * @version 1.0, Nov 26, 1996
- * @author Symantec
- */
-
- // 02/15/97 RKM Added change checking on setter before invalidating
- // Added range checking in setValue
- // 02/27/97 RKM Merged Scott's change to call invalidate in setValue
-
- //???RKM??? Shouldn't all of these invalidate calls be repaint
-
- public abstract class Slider
- extends Canvas
- {
- /**
- * Defines the slider tick style where the tick marks appear to the left of
- * the slider thumb.
- */
- public static final int TICK_LEFT = 0;
-
- /**
- * Defines the slider tick style where the tick marks appear to the right of
- * the slider thumb.
- */
- public static final int TICK_RIGHT = 1;
-
- /**
- * Defines the slider tick style where the tick marks appear below
- * the slider thumb.
- */
- public static final int TICK_BOTTOM = 0;
-
- /**
- * Defines the slider tick style where the tick marks appear above
- * the slider thumb.
- */
- public static final int TICK_TOP = 1;
-
- /**
- * Defines the slider tick style where the tick marks appear both
- * to the left and right of the slider thumb.
- */
- public static final int TICK_BOTH = 2;
-
- /**
- * Disables the display of slider tick marks.
- */
- public static final int TICK_NONE = 3;
-
- /**
- * (not used).
- */
- protected boolean enabled;
- /**
- * The current component width.
- */
- protected int width;
- /**
- * The current component height.
- */
- protected int height;
- /**
- * The current slider tick mark style.
- */
- protected int style;
- /**
- * The current tick mark display frequency.
- */
- protected int freq;
- /**
- * The minimum value of the slider range.
- */
- protected int min;
- /**
- * The maximum value of the slider range.
- */
- protected int max;
- /**
- * The position of the slider thumb last time control painted.
- */
- protected int prevPos;
- /**
- * The current position of the slider thumb.
- */
- protected int curPos;
- /**
- * Flag indicating if border should be drawn.
- */
- protected boolean showBorder;
-
- /**
- * Constructs the Slider.
- */
- protected Slider()
- {
- }
-
- /**
- * Returns the current slider tick mark style.
- * @return one of TICK_LEFT, TICK_RIGHT, TICK_TOP, TICK_BOTTOM, TICK_BOTH, or TICK_NONE
- */
- public int getTickStyle()
- {
- return style;
- }
-
- /**
- * Sets the minimum value of the slider range.
- * @param min the new minimum slider value
- * @see #getMinValue
- * @see #setMaxValue
- */
- public void setMinValue(int min)
- {
- if (this.min != min)
- {
- this.min = min;
-
- invalidate();
- }
- }
-
- /**
- * Returns the current minimum value of the slider range.
- * @see #setMinValue
- * @see #getMaxValue
- */
- public int getMinValue()
- {
- return min;
- }
-
- /**
- * Sets the maximum value of the slider range.
- * @param max the new maximum slider value
- * @see #getMaxValue
- * @see #setMinValue
- */
- public void setMaxValue(int max)
- {
- if (this.max != max)
- {
- this.max = max;
-
- invalidate();
- }
- }
-
- /**
- * Returns the current maximum value of the slider range.
- * @see #setMaxValue
- * @see #getMinValue
- */
- public int getMaxValue()
- {
- return max;
- }
-
- /**
- * Sets the tick mark display frequency.
- * @param freq the range in value between tick marks
- * @see #getTickFreq
- */
- public void setTickFreq(int freq)
- {
- if (this.freq != freq)
- {
- this.freq = freq;
-
- invalidate();
- }
- }
-
- /**
- * Returns the current tick mark display frequency.
- * @return the range in value between tick marks
- * @see #setTickFreq
- */
- public int getTickFreq()
- {
- return freq;
- }
-
- /**
- * Sets the slider value.
- * @param pos the new slider value
- * @see #getValue
- */
- public void setValue(int pos)
- {
- //Do range checking on pos
- if (pos < getMinValue())
- pos = getMinValue();
- else if (pos > getMaxValue())
- pos = getMaxValue();
-
- doMove((pos - min) / freq, false);
-
- repaint();
- }
-
- /**
- * Returns the current slider value.
- * @see #setValue
- */
- public int getValue()
- {
- return curPos * freq + min;
- }
-
- /**
- * Sets the border display flag.
- * @param f true for the border to show
- * @see #getShowBorder
- */
- public void setShowBorder(boolean f)
- {
- if (showBorder != f)
- {
- showBorder = f;
-
- invalidate();
- }
- }
-
- /**
- * Returns the current border display flag.
- * @return true if the border is visible
- * @see #setShowBorder
- */
- public boolean getShowBorder()
- {
- return showBorder;
- }
-
- /**
- * Enables this component so that it will respond to user input.
- * This is a standard Java AWT method which gets called to enable
- * this component. Once enabled this component will respond to user input.
- *
- * @see #disable
- */
- public synchronized void enable()
- {
- super.enable();
- }
-
- /**
- * Disables this component so that it doesn't respond to user input.
- * This is a standard Java AWT method which gets called to disable
- * this component. Once disabled this component will not respond to user
- * input.
- *
- * @see #enable
- */
- public synchronized void disable()
- {
- super.disable();
- }
-
- /**
- * Returns the recommended dimensions to properly display this component.
- * This is a standard Java AWT method which gets called to determine
- * the recommended size of this component.
- * @return the preferred size, in this case the latest reshape() size
- *
- * @see java.awt.Component#minimumSize
- */
- public Dimension preferredSize()
- {
- return new Dimension(width, height);
- }
-
- /**
- * This abstract routine updates the thumb position, paints the slider, and
- * posts a new action event, as needed. If the thumb position has
- * changed or the forcePost parameter is true the component will be painted
- * and an action event posted.
- * @param pos the new thumb position
- * @param forcePost true forces a repaint and posting of an action message
- * even if the thumb position hasn't changed
- */
- protected abstract void doMove(int pos, boolean forcePost);
- }
-
-